﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Infrastructure.Authentication;
using HROReporting.Services.Interfaces;
using HROReporting.Controllers.ActionArguments;
using System.Web.Mvc;
using HROReporting.Controllers.ViewModels.Account;
using HROReporting.Services.Messaging.DocentService;

namespace HROReporting.Controllers.Controllers
{
    public class DocentRegisterController : BaseAccountController
    {
        private readonly IDocentService _docentService;

        public DocentRegisterController(ILocalAuthenticationService authenticationService,
                                         IStudentService studentService,
                                         IFormsAuthentication formsAuthentication,
                                         IActionArguments actionArguments,
                                         IDocentService docentSerivce)
            : base(authenticationService,
                   studentService,
                   formsAuthentication,
                   actionArguments)
        {
            _docentService = docentSerivce;
        }

        public ActionResult Register()
        {
            User user;

            string password = "testing";
            string email = "j.klaas@hr.nl";
            string docentCode = "2";
            string schoolKantoor = "1";
            string voornaam = "Jan";
            string achternaam = "Klaas";

            user = _authenticationService.RegisterUser(email, password, "docent");

            if (user.IsAuthenticated)
            {
                CreateDocentRequest createDocentRequest = new CreateDocentRequest();
                createDocentRequest.DocentCodeId = Convert.ToInt16(docentCode);
                createDocentRequest.SchoolKantoorId = Convert.ToInt16(schoolKantoor);
                createDocentRequest.DocentIdentityToken = user.AuthenticationToken;
                createDocentRequest.Email = email;
                createDocentRequest.Voornaam = voornaam;
                createDocentRequest.Achternaam = achternaam;

                _formsAuthentication.SetAuthenticationToken(email);
                _docentService.CreateDocent(createDocentRequest);

                return RedirectToAction("MyDetails", "Docent");
            }
            else
            {
                return View();
            }
        }
    }
}
